// aiserve/factory.go
package aiserve

import (
	"errors"
)

// ServiceType 定义支持的AI服务类型
type ServiceType string

const (
	ServiceDoubao ServiceType = "doubao" // 豆包
	ServiceTongyi ServiceType = "tongyi" // 通义千问
)

// NewAIService 工厂函数：根据类型和配置创建AI服务实例
func NewAIService(serviceType ServiceType, config AIConfig) (AIService, error) {
	switch serviceType {
	case ServiceDoubao:
		// 补充默认配置（如果未指定）
		if config.BaseURL == "" {
			config.BaseURL = DefaultConfigs[string(ServiceDoubao)].BaseURL
		}
		if config.Model == "" {
			config.Model = DefaultConfigs[string(ServiceDoubao)].Model
		}
		return NewDoubaoAIService(config), nil
	case ServiceTongyi:
		if config.BaseURL == "" {
			config.BaseURL = DefaultConfigs[string(ServiceTongyi)].BaseURL
		}
		if config.Model == "" {
			config.Model = DefaultConfigs[string(ServiceTongyi)].Model
		}
		return NewTongyiAIService(config), nil
	default:
		return nil, errors.New("不支持的AI服务类型")
	}
}
